<?php
$tourCategory = $this->tourCategory;
$paginator    = $this->paginator;

$f = $this->form;
?>
<div style="background-color: white; width: 100%; height: auto; overflow: hidden">
    <div class="top-title">
        <div class="content-title">
            <h2><?php echo $this->translate('Enquire_Now');?>
            </h2>
        </div>
    </div>
    <div style="width:100%;margin:0px 0px 30px 20px;overflow:hidden;">
        <?php echo $this->flashMessenger()?>
        <?php if($this->error != ''): ?>
            <div class="shout-box">
                <div class="alert alert-block 0">
                    <a class="close fade in" data-dismiss="alert" href="##">×</a>
                    <p style="font-weight:bold;text-align:center"><?php echo $this->translate($this->error); ?></p>
                </div>
            </div>
        <?php endif; ?>

        <div style="width:100%;float:left;">
    		<form onsubmit="" id="inquyry_form" name="inquyry_form" method="post" action="">
    			<table style="margin:20px 0px 0px 0px;width:700px;float:left;" cellspacing="4" cellpadding="4">
    				<tbody>
    					<tr>
    						<td class="">
    							<span><?php echo $this->translate('Full_name'); ?>&nbsp;</span><span class="required">*</span>
    						</td>
    						<td>
    						    <?php echo $f->getElement('full_name'); ?>
    						</td>
    					</tr>
    					<tr>
    						<td class="">
    							<span><?php echo $this->translate('Email_address'); ?>&nbsp;</span><span class="required">*</span>
    						</td>
    						<td class="">
    							<?php echo $f->getElement('email'); ?>
    						</td>
    					</tr>
    					<tr>
    						<td class="">
    							<span><?php echo $this->translate('Reconfirm_email_address'); ?>&nbsp;</span><span class="required">*</span>
    						</td>
    						<td class="">
    							<?php echo $f->getElement('reconfirm_email'); ?>
    						</td>
    					</tr>
    					<tr>
    						<td class="">
    							<span><?php echo $this->translate('Telephone_no'); ?>&nbsp;</span>
    						</td>
    						<td class="">
    							<?php echo $f->getElement('phone'); ?>
    						</td>
    					</tr>
    					<tr>
    						<td class="">
    							<span><?php echo $this->translate('Country_of_residence'); ?>&nbsp;</span><span class="required">*</span>
    						</td>
    						<td class="">
    							<?php echo $f->getElement('country_residence'); ?>
    						</td>
    					</tr>
    					<tr>
    						<td class=""><span><?php echo $this->translate('Subject'); ?>&nbsp;</span><span class="required">*</span></td>
    						<td class="">
    							<?php echo $f->getElement('subject'); ?>
    						</td>
    					</tr>
    					<tr>
    						<td class=""><span><?php echo $this->translate('Your_Inquyry') ?>&nbsp;</span><span class="required">*</span></td>
    						<td class="">
    							<?php echo $f->getElement('inquyry'); ?>
    						</td>
    					</tr>
    					<tr>
    						<td class=""><span><?php echo $this->translate('Captcha'); ?>&nbsp;</span><span class="required">*</span></td>
    						<td class="">
    							<?php echo $f->getElement('captcha'); ?>
    						</td>
    					</tr>
    					<tr>
    						<td class="">&nbsp;</td>
    						<td class="">
    							<input type="submit" value="<?php echo $this->translate('Send_Email'); ?>" id="submit" class="btn">
    							<input type="reset" value="<?php echo $this->translate('Reset'); ?>" id="reset" class="btn">
    						</td>
    					</tr>
    					<tr>
    						<td class="" colspan="2">
    							<span><?php echo $this->translate('Fields_marked_with_asterisk_'). ' <span class="required">*</span> '. $this->translate('_are_mandatory'); ?></span>
    						</td>
    					</tr>
    				</tbody>
    			</table>
    		</form>
		</div>
    </div>
</div>


<script>
$(function(){
	var form    = $("#inquyry_form");
	var name    = $("#full_name");
	var email   = $("#email");
	var reEmail = $("#reconfirm_email");
	var subject = $("#subject");
	var inquyry = $("#inquyry");
	var countryResidence = $("#country_residence");

	name.blur(validateName);
	email.blur(validateEmail);
	reEmail.blur(validateReConfirmEmail);
	countryResidence.blur(validateCountryResidence);
	subject.blur(validateSubject);
	inquyry.blur(validateInquyry);

	form.submit(function(){
		if(validateName() && validateEmail() && validateReConfirmEmail() && validateCountryResidence() && validateSubject() && validateInquyry())
			return true;
		else
			return false;
	});
	function validateName(){
		if(name.val().length < 4){
			$(".full-name-error").remove();
			name.after("<ul class='errors full-name-error'><li><?php echo $this->translate("We_want_names_with_more_than_3_letters!"); ?></li></ul>");
			return false;
		}
		else{
			$(".full-name-error").remove();
			return true;
		}
	}

	function validateEmail(){
		var a = $("#email").val();
		var filter = /^[a-zA-Z0-9]+[a-zA-Z0-9_.-]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$/;
		if(filter.test(a)){
			$(".email-error").remove();
			return true;
		} else{
			$(".email-error").remove();
			email.after("<ul class='errors email-error'><li><?php echo $this->translate("Type_a_valid_email_please") ?></li></ul>");
			return false;
		}
	}
	function validateReConfirmEmail(){
		if( email.val() != reEmail.val() ){
			$(".re-email-error").remove();
			reEmail.after("<ul class='errors re-email-error'><li><?php echo $this->translate("Reconfirm_email_doesn't_match!") ?></li></ul>");
			return false;
		}
		else{
			$(".re-email-error").remove();
			return true;
		}
	}
	function validateCountryResidence(){
		if(countryResidence.val().length == 0){
			$(".country-residence-error").remove();
			countryResidence.after("<ul class='errors country-residence-error'><li><?php echo $this->translate("Value_is_required_and_can't_be_empty!") ?></li></ul>");
			return false;
		}
		else{
			$(".country-residence-error").remove();
			return true;
		}
	}
	function validateSubject(){
		if(subject.val().length < 10){
			$(".subject-error").remove();
			subject.after("<ul class='errors subject-error'><li><?php echo $this->translate("We_want_subject_with_more_than_10_letters!") ?></li></ul>");
			return false;
		}
		else{
			$(".subject-error").remove();
			return true;
		}
	}
	function validateInquyry(){
		if(inquyry.val().length == 0){
			$(".inquyry-error").remove();
			inquyry.after("<ul class='errors inquyry-error'><li><?php echo $this->translate("Value_is_required_and_can't_be_empty!") ?></li></ul>");
			return false;
		}
		else{
			$(".inquyry-error").remove();
			return true;
		}
	}
});


$('.close').click(function() {
	$('.shout-box').remove();
});

</script>